package com.sjs.boot.dynamic.protocol;

/**
 * @author uto_dev_008
 * @desc
 * @since 2021/11/9 18:23
 */
public enum RetCode {
    OK(0, "Success"),
    INTERNAL_ERROR(1, "Internal error"),
    UNKNOWN_ERROR(2, "unknown key"),
    ERROR_404(404, "unknown resource"),
    RESOURSE_MISS_ERROR(10000001, "[%s]资源缺失"),
    //140000+ 参数问题，140001表示第一个参数，以此类推
    WRONG_PARAMETER(140000, "Wrong parameter");


    private int code;
    private String msg;

    private RetCode(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public String getMsg() {
        return getMsg("");
    }

    public String getMsg(String arg) {
        return String.format(this.msg, arg);
    }

    public static  String getMsg(int code) {
        RetCode[] dapRetCodes =   RetCode.values();
        for (int i = 0; i < dapRetCodes.length; i++) {
            if (dapRetCodes[i].getCode()==code) {
                return dapRetCodes[i].getMsg();
            }
        }
        return RetCode.UNKNOWN_ERROR.getMsg();
    }

    public int getCode() {
        return this.code;
    }
}
